package com.qiaoanju.back.dao.system;

import com.qiaoanju.back.domain.system.MenuModel;
import com.qiaoanju.dao.SqlMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * Created by eversec on 2017/9/21.
 */
public interface IMenuDao extends SqlMapper {


    /**
     *
     * @param menu
     * @return
     */
    @Insert("insert into t_menu(menu_name, menu_url, pid, role_id, enable, menu_type, menu_level, create_id) values(#{menu_name}, #{menu_url}, #{pid}," +
            "#{role_id}, #{enable}, #{menu_type}, #{menu_level}, #{create_id})")
    int insert(MenuModel menu);

    @Delete("delete from t_menu where id = #{id}")
     int deleteById(int id);

    @Update("update t_menu set menu_name = #{menu_name}, menu_url = #{menu_url}, pid = #{pid}, role_id = #{role_id}, enable = #{enable}, menu_type = #{menu_type}, menu_level = #{menu_level}, " +
            "update_time = #{update_time}, update_id = #{update_id} where id = #{id}")
    boolean edit(MenuModel user);

    @Select("select * from t_menu where id = #{id}")
     MenuModel getMenuById(int id);

    @Select("select * from t_menu")
     List<MenuModel> getAllUsers();

    @Select("select * from t_menu where pid = #{pid}")
    List<MenuModel> getchildByPid(int pid);


    /**
     * 根据id获取父菜单和子菜单
     * @param id
     * @return
     */
    List<MenuModel> getParentAndChildMenus(int id);

    @Select("SELECT * FROM t_menu ORDER BY create_time ")
    List<MenuModel> getMenusList();

}
